package com.navinfo.platform.common.service.impl;

import com.navinfo.platform.common.service.ILoadDataChannel;
import org.apache.spark.sql.SparkSession;

import java.util.Map;

public enum LoadDataFromMysql implements ILoadDataChannel {
    //
    INSTANCE;

    @SuppressWarnings("unchecked")
    @Override
    public <T> T readData(SparkSession spark, Object ... param) {
        Map<String, String> config = (Map<String, String>) param[0];
        String url = config.get("url");
        String tablename = config.get("tablename");
        String user = config.get("user");
        String password = config.get("password");
        return (T) spark.read()
             .format("jdbc")
             .option("url", url)
             .option("dbtable", tablename)
             .option("user", user)
             .option("password", password)
             .load();

    }
}
